# 项目：python_project
# 文件：Demo4
# 作者：WuTong
# 日期：2025/5/23,14:37
# coding:utf-8
from PythonProject.Demo3 import Util


class KeyWord:

    driver = None

    def open_browser(self,browser):
        from selenium import webdriver
        if hasattr(webdriver,browser):
            self.driver = getattr(webdriver,browser)()
            self.driver.implicitly_wait(5)
            self.driver.maximize_window()
        return self.driver

    def open_page(self,url):
        self.driver.get(url)

    def input(self,element,value):
        elements = self.driver.find_element('css selector',element)
        elements.click()
        elements.clear()
        elements.send_keys(value)

    def click(self,value):
        self.driver.find_element('css selector', value).click()

    def sleep(self,value):
        from time import sleep
        sleep(int(value))

    def find_ele(self, what):
        try:
            ele = self.driver.find_element('css selector', what)
            actual = ele.text
        except Exception as e:
            actual = 'not found'
        print(actual)
        return actual


    def assert_equal(self, what, expect):
        actual = self.find_ele(what)
        assert actual == expect

    def close(self):
        self.driver.close()

    def refresh(self):
            self.driver.refresh()

def test_run():
    scripts = Util.read_csv('smscripe.csv')
    keymap = Util.read_json('conf.json')['keys']
    kw = KeyWord()
    for step in scripts:
        key = step.split(', ')[0]
        ekey = keymap[key]
        params = step.split(', ')[1:]
        if hasattr(kw, ekey):
            getattr(kw, ekey)(*tuple(params))


if __name__ == '__main__':
    pass